package com.exam.serviceimpl;
import com.exam.entity.StudentScore;
import com.exam.mapper.StudentScoreRepository;
import com.exam.service.StudentScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentScoreServiceImpl implements StudentScoreService {

    @Autowired
    private StudentScoreRepository studentScoreRepository;

    @Override
    public Page<StudentScore> getScoresByStudentId(Integer studentId, Pageable pageable) {
        return studentScoreRepository.findByStudentId(studentId, pageable);
    }

    @Override
    public List<StudentScore> getScoresByStudentIdAndCourse(Integer studentId, String courseName) {
        return studentScoreRepository.findByStudentIdAndCourseName(studentId, courseName);
    }

    @Override
    public StudentScore saveOrUpdateScore(StudentScore studentScore) {
        return studentScoreRepository.save(studentScore);
    }

    @Override
    public void deleteScoreById(Integer scoreId) {
        studentScoreRepository.deleteById(scoreId);
    }
}